#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <fcntl.h>
#include <string.h>

int main() {

    int fd, fd2, num0fReads;
    char buffer[100];

    fd = open("random_text.txt", O_RDWR | O_CREAT, 0777);
    fd2 = open("modified_text.txt", O_RDWR | O_CREAT, 0777);

    if (fd < 0 | fd2 < 0) {
        printf("Error!\n");
    }

    int readCount = read(fd, buffer, 100);
        
     while (readCount > 0) {
        printf("%.*s\n", readCount, buffer);
        readCount = read(fd, buffer, 100);
    }

    if (num0fReads % 2 == 0) {
        write(fd2, "Even Read!\n", 10);s
        
    } else {
        write(fd2, buffer, 100);
        write(fd2, "\n", 1);
    }  
    readCount = read(fd, buffer, 100);
    num0fReads++;

    if (close(fd) < 0 | close(fd2) < 0) {
        printf("Error\n");
        exit(1);
    }
}